<?php 
require_once '../../config.php';
require_once '../../function.php';
//获取用户头像和昵称，返回给前端生成
//因为获取用户的头像和昵称，需要用户的id ，用户登录的时候系统会将ID放到session里面，只需要从session获得；
//开启session;
session_start();
//获取id
$userId = $_SESSION['user_id'];
//根据用户的id到数据库中查找需要查询的头像和昵称
//1.连接数据库
$connect =connect();
//2.准备sql语句
$sql = "select * from users where id = {$userId}";
//3.执行查询
$queryResult = query($connect,$sql);
//判断是否查询到数据，返回到前端
$response = ["code"=>0,"msg"=>"操作失败"];
if ($queryResult) {
    $response["code"] = 1;
    $response["msg"] = "操作成功";
    $response["avatar"] = $queryResult[0]['avatar'];
    $response["nickname"] =$queryResult[0]['nickname'];
}
//5.以json格式返回
header("content-type:application/json;charset=utf-8");
echo json_encode($response);
 ?>